package com.example.hellonotes.bmob;



import android.content.Context;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.listener.SaveListener;

public class UserProxy {

	private Context mContext;
	
	public UserProxy(Context context){
		this.mContext = context;
	}
	
	
	/**
	 * 用户注册的方法
	 * @param userName
	 * @param password
	 * @param email
	 */
	public void singup(String userName,String password,String email) {
	BmobUser user = new BmobUser();
	user.setUsername(userName);
	user.setPassword(password);
	user.setEmail(email);
	user.signUp(mContext, new SaveListener() {
		
		
		@Override
		public void onSuccess() {
			// TODO 自动生成的方法存根
			System.out.println("注册成功");
			
		}
		
		@Override
		public void onFailure(int arg0, String msg) {
			// TODO 自动生成的方法存根
			System.out.println("注册失败"+msg);
		}
	});
}
	/**
	 * 接口  注册 成功和失败的两个回调方法  以便调用时直接重写
	 * @author Administrator
	 *
	 */
	public interface ISignUpListener{
		void onSignUpSuccess();
		void onSignUpFailure(String msg);
	}
	private ISignUpListener signUpLister;
	public void setOnSignUpListener(ISignUpListener signUpLister){
		this.signUpLister = signUpLister;
	}
	
	/**
	 * 用户登录的方法
	 * @param userName
	 * @param password
	 */
	public void login(String userName,String password){
	
		BmobUser user = new BmobUser();
		user.setUsername(userName);
		user.setPassword(password);
		
		user.login(mContext, new SaveListener() {
			
			@Override
			public void onSuccess() {
				// TODO Auto-generated method stub
				if(loginListener != null){
					loginListener.onLoginSuccess();
				}else{
				}
			}

			@Override
			public void onFailure(int arg0, String msg) {
				// TODO Auto-generated method stub
				if(loginListener != null){
					loginListener.onLoginFailure(msg);
				}else{
				}
			}
		});
	}
	/**
	 * 接口  登录成功和失败的两个方法 
	 * @author Administrator
	 *
	 */
	public interface ILoginListener{
		void onLoginSuccess();
		void onLoginFailure(String msg);
	}
	
	private ILoginListener loginListener;
	public void setOnLoginListener(ILoginListener loginListener){
		this.loginListener  = loginListener;
	}
	
}
